﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Text;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Base;
using iBeauty.BLL;
using iBeauty.BusinessObjects;

namespace iBeauty.App.UCControl
{
    public partial class StaffUc : XtraUserControl
    {
        private List<Staff> _currentSelection;

        #region Contructor

        public StaffUc()
        {
            InitializeComponent();
            grvStaff.CustomUnboundColumnData += grvStaff_CustomUnboundColumnData;
        }

        #endregion

        #region Event handle

        private void StaffUc_Load(object sender, EventArgs e)
        {
            LoadStaffs();
        }

        private void grvStaff_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e)
        {
            if (e.IsGetData)
                e.Value = e.ListSourceRowIndex + 1;
        }

        private void btnShowAll_Click(object sender, EventArgs e)
        {
            LoadStaffs();
        }

        private void btnShowSelected_Click(object sender, EventArgs e)
        {
            var selectedRows = grvStaff.GetSelectedRows();
            var selectedStaff = new List<Staff>();

            for (int i = 0; i < selectedRows.Length; i++)
            {
                var staff = (Staff)grvStaff.GetRow(selectedRows[i]);
                selectedStaff.Add(staff);
            }

            _currentSelection = selectedStaff;

            GridStaff.DataSource = _currentSelection;
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            var search =new frmSearch();
            search.SearchEvent += SearchData;
            search.ShowDialog();
        }

        #endregion

        #region Private method

        private void LoadStaffs()
        {
            var staffBll = new StaffBLL();
            _currentSelection = staffBll.GetStaffs();
            GridStaff.DataSource = _currentSelection;
        }

        private void SearchData(object sender, EventArgs e)
        {
            XtraMessageBox.Show("Tim kiem");
        }

        #endregion

    }
}
